Ext.define('SA.store.Languages', {
	extend: 'Ext.data.Store',

    autoLoad: true,
    autoSync: false,
	remoteSort: false,
	buffered: false,
	
	proxy: {
		api: {
			read: applicationBase + "prototype/languages.action"
		},
    	type: "ajax",
    	reader: {
    		type: "json",
    		totalProperty: "data.totalCount",
    		root: "data.languageStore",
    		messageProperty: "data.message"
    	},
    	writer: {
    		allowSingle: false,
    		type: "json",
    		root: "language"
    	},
    	listeners: {
    		"exception": function(proxy, response, operation) {
    		    // Ext JS 4.0.2 does not handle this exception!
    		    switch (operation.action) {
   		            case 'create':
   		                Ext.each(operation.records, function(record) {
   		                    record.store.remove(record);
   		                });
   		                break;
   		                            
   		            case 'destroy':
   		                Ext.each(operation.records, function(record) {
   		                    if (record.removeStore) {
   		                        record.removeStore.insert(record.removeIndex, record);
   		                        record.removeStore.removed = [];
   		                    }
   		                });
   		                break;
    		    }
    	        Ext.MessageBox.show({
    	            title: 'Data Access Error',
    	            msg: operation.error,
    	            buttons: Ext.MessageBox.OK,
    	            icon: Ext.MessageBox.ERROR
    	        });
    		}
    	} 
	},
	model: 'SA.model.Language',
	
	listeners: {
		"remove": function(store, record, index) {
		    record.removeStore = store;
		    record.removeIndex = index;
		}
	}
});